package cn.fufeiii.bt.demo.knife4j;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.*;
import java.util.Date;

/**
 * @author FuFei
 */
@Tag(name = "测试模块openapi3")
@RestController
@RequestMapping("/knife4j")
public class Knife4jController {


    @Operation(summary = "增加数据")
    @PostMapping("/add")
    public AddParam add(@RequestBody AddParam addParam) {
        return addParam;
    }


    @Getter
    @AllArgsConstructor
    public enum SexEnum {
        MALE(1), FEMALE(2),
        ;
        private final Integer code;
    }

    @Data
    @Schema
    public static class AddParam {
        @NotBlank
        @Size(min = 1, max = 32)
        @Schema(description = "姓名")
        private String name;

        @Min(0)
        @Max(100)
        @NotNull
        @Schema(description = "年龄")
        private Integer age;

        @Pattern(regexp = "[1|2]")
        @NotBlank
        @Schema(description = "性别 1-男 2-女")
        private String sex;

        @Past
        @NotNull
        @Schema(description = "生日")
        private Date birthday;

    }

}
